#include <iostream>
#include <fstream>
#include <ctime>
#include <vector>
#include <string>
using namespace std;

int stringToInt(string str) {
    int res = 0;
    for (auto& i: str) res = res * 10 + ((int)i - 48);
    return res;
}

void BubbleSort (string file_name) {
    float t = clock();
    vector<int> arr;
    ifstream readFile(file_name);
    string line;

    if (readFile.is_open()) {
        while (getline(readFile, line)) {
            arr.push_back(stringToInt(line));
        }
    }
    for (int i = 0; i < (int)arr.size(); i++) {
        for (int j = 0; j <(int)arr.size() - 1; j++) {
            if (arr[j] > arr[j + 1]) {
                int temp = arr[j];
                arr[j] = arr[j+1];
                arr[j+1] = temp;
            }
        }
    }
    float t2 = clock();
    for (auto& i : arr) cout << i << '';
    cout << "\nTime sorted by:" << (t2 - t) / CLOCKS_PER_SEC << '\n';
    readFile.close();
}
int main() {
    cout << "Array 1\n";
    BubbleSort("m1_sorted.txt");
    cout << "Array 2\n";
    BubbleSort("m2_sorted.txt");
    cout << "Array 3\n";
    BubbleSort("m3_sorted.txt");
}